{% extends "_base.html" %}


{% block  title %}资产信息{% endblock %}

{% block page-content %}


    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>资产管理</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="/">主页</a>
                </li>
                <li>物理机管理
                </li>
                <li class="active">
                    <strong>物理机列表</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>资产信息</h5>

                    </div>
                    <div class="ibox-content">

                          <div class="table-responsive">

                            <a href="{% url 'cmdb:host_add' %}?t=1" class="btn btn-primary  ">
                                添加</a>

                            <a class="btn btn-danger" data-toggle="modal"
                               data-target="#myModal2">批量删除
                            </a>





                            <form id="del_form_asset_all" class="form-horizontal  ">
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" id="CheckedAll"></th>
                                        <th>名称</th>
                                        <th>主机名</th>
                                        <th>管理IP</th>
                                        <th>安全区域</th>
                                        <th>配置更新</th>
                                        <th>动作{{ error_performance }}</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   hosts %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                            <td><input type="checkbox" value="{{ row.id }}"  name="id"></td>
                                            <td class="center"><a
                                                    href="{% url 'cmdb:host' %}/{{ row.id }}/">{{ row.name }}</a>
                                            </td>
                                            <td class="center">{{ row.hostname }}</td>
                                            <td class="center">{{ row.ip }}</td>
                                            <td class="center">{{ row.group }}</td>
                                            <td class="center">{{ row.agenttime }}</td>
                                            <td>
                                                <a class="btn btn-info  btn-xs " href="{% url  'cmdb:host' %}?m={{ row.id }}">虚拟化清单</a>
                                                <a class="btn btn-primary  btn-xs " href="/admin/cmdb/host/{{ row.id }}/change/" target="_blank">详细信息</a>
                                                <a class="btn btn-danger  btn-xs  asset_del_id"     data-toggle="modal"
                                                        data-target="#myModal1">删除
                                                </a>
                                                <a class="btn btn-xs btn-success" href="{% url  'cmdb:webssh' %}#webssh_{{ row.id }}" target="_blank">终端</a>
                                                <a class="btn btn-xs btn-warning" href="{% url  'cmdb:webssh' %}#sftp_{{ row.id }}" title="SFTP" target="_blank">文件</a>

                                            </td>
                                        </tr>
                                    {% endfor %}

                                    </tbody>

                                </table>
                            </form>


                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <i class="fa fa-clock-o modal-icon"></i>
                    <h4 class="modal-title">删除</h4>
                    <span id="error" style="color:red;"></span>
                    <small></small>
                </div>
                <form id="asset_del_form">
                    <div class="modal-body">

                        <div class="form-group"><input type="text" name="nid" style="display:none"/></div>
                        <p><strong>确定删除？</strong></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <a class="btn btn-danger m-r-sm asset_del">删除</a>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <i class="fa fa-clock-o modal-icon"></i>
                    <h4 class="modal-title">批量删除</h4>
                    <span id="error_all" style="color:red;"></span>
                    <small></small>
                </div>
                <form id="del_form">
                    <div class="modal-body">

                        <p><strong>确定删除？</strong></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <a class="btn btn-danger m-r-sm  asset_all_del"> 批量删除</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

{% endblock %}



{% block footer-js %}


        <script>
            $(function () {

                $('.asset_del_id').click(function () {
                    var id = $(this).parent().parent().attr('id');
                    $('#asset_del_form').find('input[name="nid"]').val(id);


                });
                $('.asset_del').click(function () {
                    $.ajax({
                        url: "/cmdb/host/del",
                        type: 'POST',
                        data: $('#asset_del_form').serialize(),
                        success: function (data) {
                            var obj = JSON.parse(data);
                            if (obj.status) {
                                location.reload()
                            } else {
                                $('#error').text(obj.error);
                            }
                        }
                    })
                });

                $('.asset_all_del').click(function () {
                    $.ajax({
                        url: "/cmdb/host/alldel",
                        type: 'POST',
                        data: $('#del_form_asset_all').serialize(),
                        success: function (data) {
                            var obj = JSON.parse(data);
                            if (obj.status) {
                                location.reload()
                            } else {
                                $('#error_all').text(obj.error);
                            }
                        }

                    })
                });


            });



        </script>

{% endblock %}
